home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / OS⁄Toolbox / LaunchWithDoc / LaunchWithDoc.c next >
Encoding:
C/C++ Source or Header  |  1991-06-27  |  3.5 KB  |  108 lines  |  [TEXT/MPS ]

  1. /* LaunchWithDoc */
  2. /* The smallest LaunchAplication example I could come up with. */
  3. /* this launches an application with a 'odoc' event */
  4. /* this little bit of code here uses two Standard File calls to get */
  5. /* the doc to launch and the file to launch with, you will of course */
  6. /* want to replace these with whatever you want to do */
  7. /* ••• NOTE: Thsi also works for launching non-System 7 applications.  */
  8. /* If the Finder™ sees an 'odoc' or 'pdoc' Apple event in the launch block */
  9. /* and the application being launched is NOT system 7 aware, the Finder */
  10. /* coerces the Apple event into puppetstrings.  So you */
  11. /* don't need to special case for non-7.0 applications.  */
  12. /* Pretty neat, huh? */
  13. /* ••• Important: I'm not doing any error checking, you of course should */
  14. /* so your users don't hunt you down and burn your keyboard. */
  15. /* C.K. Haun */
  16. /* DTS */
  17. #include <Dialogs.h>
  18. #include <QuickDraw.h>
  19. #include <Windows.h>
  20. #include <Menus.h>
  21. #include <Fonts.h>
  22. #include <appleevents.h>
  23. #include <processes.h>
  24. #include <files.h>
  25. #include <StandardFile.h>
  26. #include <Aliases.h>
  27.  
  28. main()
  29. {
  30.  
  31. FSSpec l1,f1;  /* file spec for the app (l1) and the file (f1) */
  32. LaunchParamBlockRec launchThis;
  33. AEDesc myAddress;
  34. AEDesc docDesc,launchDesc;
  35. AEDescList theList;
  36. AliasHandle withThis;
  37. StandardFileReply myReply;
  38. AppleEvent theEvent;
  39.  
  40.  
  41.  
  42.        InitGraf((Ptr)&qd.thePort);
  43.     InitFonts();
  44.     InitWindows();
  45.     InitMenus();
  46.     TEInit();
  47.     InitDialogs(nil);
  48.     InitCursor();
  49. /* get the app to launch */
  50.  StandardGetFile(nil,
  51.                   -1,
  52.                   nil,
  53.                              &myReply);
  54. if(!myReply.sfGood)return;        
  55. l1=myReply.sfFile;
  56. launchThis.launchAppSpec=&l1;
  57.  
  58. /* get the file to pass */
  59.  StandardGetFile(nil,
  60.                   -1,
  61.                   nil,
  62.                   &myReply);                
  63. if(!myReply.sfGood)return;    
  64.  
  65. /* the caller may have already done this, but it doesn't hurt to do it again */
  66. f1=myReply.sfFile;
  67. /* create an appleevent to carry it */
  68. AECreateAppleEvent(kCoreEventClass,kAEOpenDocuments,&myAddress,kAutoGenerateReturnID, kAnyTransactionID,&theEvent);
  69. /* create a list for the alaises.  In this case, I only have one, but you still need */
  70. /* a list */
  71. AECreateList(nil,
  72. 0,
  73. false,
  74. &theList);
  75. /* create an alias out of the file spec */
  76. /* I'm not real sure why I did this, since there is a system coercion handler for */
  77. /* alias to FSSpec, but I'm paranoid */
  78. NewAlias(nil,&f1,&withThis);
  79. HLock((Handle)withThis);
  80. /* now create an alias descriptor */ 
  81. AECreateDesc(typeAlias,(Ptr)*withThis,GetHandleSize((Handle)withThis),&docDesc);
  82. HUnlock((Handle)withThis);
  83. /* put it in the list */
  84. AEPutDesc(&theList,0,&docDesc);
  85. AEPutParamDesc (&theEvent, keyDirectObject, &theList);
  86. /* coerce the event from being an event into being appParms */
  87. AECoerceDesc (&theEvent, typeAppParameters, &launchDesc);
  88. HLock((Handle)theEvent.dataHandle);
  89. /* and stuff it in the parameter block */
  90. /* This may look a little weird, since we're actually moving the evetn out of the */
  91. /* AppParameters descriptor.  But it's necessary, the coercison to typeAppParameters */
  92. /* takes the 'aevt' and puts it all in one handle, instead of */
  93. /* leaving it as a AEDesc.  So, only one handle is being added to */
  94. /* the launch parameter block instead of an AEDesc */
  95. launchThis.launchAppParameters=(AppParametersPtr)*(launchDesc.dataHandle);
  96. /* launch the thing */
  97. launchThis.launchBlockID = extendedBlock;
  98. launchThis.launchEPBLength = extendedBlockLen;
  99. launchThis.launchFileFlags=nil;
  100. launchThis.launchControlFlags=  launchContinue + launchNoFileFlags ;
  101. LaunchApplication(&launchThis);
  102. /* and launch it */
  103.  
  104.     
  105.     
  106. }
  107.  
  108.